package exercise.jslide.jslide.controller;

import exercise.jslide.jslide.app.AppContext;
import exercise.jslide.jslide.model.SlideElement;
import exercise.jslide.jslide.model.image.ImageElement;
import exercise.jslide.jslide.view.MainView;
import javafx.scene.image.Image;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class ImageController {
    private AppContext appContext;
    private FileController fileController;
    private MainView view;


    public ImageController(MainView mainView) {
        this.appContext = AppContext.getInstance();
        fileController = new FileController(appContext.getPrimaryStage());
        this.view = mainView;

    }

    public void openImage() {
        String fileName = fileController.openImageToSlide();
        if(fileName != null){
            SlideElement element = createImageElement(fileName);
            element.setX(10);
            element.setY(10);
            element.setWidth(200);
            element.setHeight(200);
            appContext.getCurrentPresentation().getCurrentSlide().addElement(element);
            view.updateView();
        }

    }

    public SlideElement createImageElement(String fileName){
        ImageElement imageElement = new ImageElement();
        imageElement.setFileName(fileName);
        imageElement.setFilePath(appContext.getCurrentPresentation().getPresentationTempFilePath()+ File.separator+"images"+File.separator);
        return imageElement;
    }

}
